import { useState, useEffect } from 'react';
import NotificationCenter from '../utils/notification';
import SwitchConfig from '../utils/switch';

const result = {
    boolForKey: SwitchConfig.boolForKey,
    arrayForKey: SwitchConfig.arrayForKey,
    dicForKey: SwitchConfig.dicForKey,
    objectForKey: SwitchConfig.objectForKey,
    numberForKey: SwitchConfig.numberForKey
}

const useSwitch = () => {
    const [config, setConfig] = useState(result)
    useEffect(() => {
        const handleConfigChange = () => {
            setConfig({ ...result })
        }
        NotificationCenter.observer('NotificationSwitchConfigName', handleConfigChange)
        return () => {
            NotificationCenter.removeObserver('NotificationSwitchConfigName')
        }
    }, []);

    return [config]
}

export default useSwitch

